package 强化训练;

import java.util.Scanner;

public class day25树根 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            String s = sc.next();
            System.out.println(rootOfNum(s));
        }
    }
    public static String rootOfNum(String n){
        if(n.length() < 2){
            return n;
        }
        char[] ch = n.toCharArray();
        int m = 0;
        for(char c : ch){
            m += c - '0';
        }
        return rootOfNum(String.valueOf(m));
    }
}
